// LabelTable.cpp: implementation of the CLabelTable class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "8085.h"
#include "LabelTable.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CLabelTable::CLabelTable()
{
    m_nLastLookedUp = 0;
    //m_LabelTable.RemoveAll();
    ++nCount;
    m_nCount=0;
}

CLabelTable::~CLabelTable()
{
    for(int i=0; i<m_nCount ; i++)
        delete [] (m_szLabel[i]);
}

//////////////////////////////////////////////////////////////////////
// Implementation
//////////////////////////////////////////////////////////////////////
int CLabelTable::Add(char *label,int address)
{
    //m_LabelTable.SetAt(label,address);
    if(m_nCount>MAX_LABELS) return 0;
    m_szLabel[m_nCount] = new char [strlen(label)+1];
    strcpy(m_szLabel[m_nCount],label);
    m_nAddress[m_nCount++] = address;
    return 1;
}
//////////////////////////////////////////////////////////////////////
// 
int CLabelTable::Search(char *str)
{
    //int x = m_LabelTable.GetCount();
    for(int i=0; i<m_nCount ; i++)
        if(strcmp(str,m_szLabel[i])==0)
        {
            m_nLastLookedUp = m_nAddress[i];
            return 1;
        }
    return 0;
    //return m_LabelTable.Lookup(str,m_nLastLookedUp);
}

void CLabelTable::Reset()
{
    for(int i=0; i<m_nCount ; i++)
        delete [] (m_szLabel[i]);
    m_nLastLookedUp = 0; m_nCount=0;
    //m_LabelTable.RemoveAll();
}


int CLabelTable::nCount =0;

